﻿using System;
using wojilu.ORM;

namespace wojilu.Apps.Qycms.Domain
{
    [Table("ybb_advert")]
    [Serializable]
    public class Advert : ObjectBase<Advert>
    {
        public Advert() { }

        public Advert(Int32 pid, Int64 atid, String lng, String title, String filename, String Url, String content, Int32 adtype, Int32 click, Int32 istime, DateTime starttime, DateTime endtime, DateTime addtime, Int32 isclass, Int32 islink, Int32 gotoid)
        {
            this.pid = pid;
            this.atid = atid;
            this.lng = lng;
            this.title = title;
            this.filename = filename;
            this.url = Url;
            this.content = content;
            this.adtype = adtype;
            this.click = click;
            this.istime = istime;
            this.starttime = starttime;
            this.endtime = endtime;
            this.addtime = addtime;
            this.isclass = isclass;
            this.islink = islink;
            this.gotoid = gotoid;
            this.insert();
        }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 pid { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int64 atid { get; set; }

        [NotNull(""), Column(Length = 50)]
        public String lng { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String title { get; set; }

        [Column(Length = 200)]
        public String filename { get; set; }

        [NotNull(""), Column(Length = 200)]
        public String url { get; set; }

        [LongText]
        public String content { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 adtype { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 click { get; set; }

        [TinyInt, Column(Length = 1), NotNull(""), Default(0)]
        public Int32 istime { get; set; }

        [NotNull("")]
        public DateTime starttime { get; set; }

        [NotNull("")]
        public DateTime endtime { get; set; }

        [NotNull("")]
        public DateTime addtime { get; set; }

        [TinyInt, Column(Length = 1), NotNull(""), Default(1)]
        public Int32 isclass { get; set; }

        [TinyInt, Column(Length = 1), NotNull(""), Default(1)]
        public Int32 islink { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 gotoid { get; set; }

        [NotSave]
        public String adtypename
        {
            get
            {
                Advert_Type a = Advert_Type.findById(atid);
                if (a == null) return String.Empty;
                return a.adtypename;
            }
        }

        [NotSave]
        public String gotourl
        {
            get
            {
                if (islink == 1)
                {
                    return url;
                }
                else
                {
                    var d = Document.findById(gotoid);
                    if (d == null)
                    {
                        return String.Empty;
                    }
                    return d.readlink;
                }
            }
        }

    }
}
